﻿

#region NameSpace
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using EB.Generics;
#endregion
/// <summary>
/// Summary description for FrameWorkMain
/// </summary>


namespace FrameWorkMain
{

  

    /// <summary>
    /// Class Contains Populate Menu from Database and Populate Inbox
    /// </summary>
    public partial class FrameWorkMain
    {
        #region Fields
        string connectionString = string.Empty;
        #endregion

        #region Constructor

        #endregion

        #region Methods

        /// <summary>
        /// Load Menu From Database
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        public DataSet GetMenu(string role)
        {
           // connectionString = "Data Source=198.64.249.24,1092;Initial Catalog=eInternShip;User Id=bmjobmjo;Password=goodhopealways";// ConfigurationManager.ConnectionStrings["connectUserManager"].ToString();

            connectionString = ConfigurationManager.ConnectionStrings["connectUserManager"].ToString();

            DataSet menuDS = new DataSet();
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                string query = string.Empty;
                if (string.IsNullOrEmpty(role))
                {
                    query = "SELECT     Menu.MenuID, Menu.Text, Menu.ParentID, Menu.Role, ModuleControlCollection.ControlName, ModuleControlCollection.ControlPath, ModuleControlCollection.IconPath, ModuleControlCollection.BackgroundColor, ModuleList.IconPath AS ModulePath, ModuleControlCollection.RequestTypeID FROM         Menu INNER JOIN   ModuleControlCollection ON Menu.ComponentID = ModuleControlCollection.ComponentID INNER JOIN  ModuleList ON ModuleControlCollection.ModuleID = ModuleList.ModuleID";
                }
                else
                {
                    query = "Select MenuID, Text, ParentID from Menu where role='" + role + "'";
                }

                SqlDataAdapter da = new SqlDataAdapter(query, conn);
                da.Fill(menuDS);
                //da.Dispose();
            }
            menuDS.DataSetName = "Menus";
            menuDS.Tables[0].TableName = "Menu";
            DataRelation relation = new DataRelation("ParentChild",
                            menuDS.Tables["Menu"].Columns["MenuID"],
                            menuDS.Tables["Menu"].Columns["ParentID"], true);

            relation.Nested = true;
            menuDS.Relations.Add(relation);
            return menuDS;
        }

        ///// <summary>
        ///// Use if needed
        ///// </summary>
        ///// <returns></returns>
        DataSet GetSubMenu(int menuID)
        {
            return new DataSet();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
      

        public DataSet GetInboxDetails()
        {
             #region Fields
            string query = string.Empty;
            DataSet inboxDS;
            #endregion

            inboxDS = new DataSet();
            query = "SELECT    isnull(UserDetails_1.UD_FirstName,'') + ' ' + isnull(UserDetails_1.UD_MiddleName,'')+ ' ' +isnull(UserDetails_1.UD_LastName,'') as RequesterName, RequestTypeList.RequestName, InBox.Status,"
                     + " InBox.Note,convert(varchar,InBox.DateOfCreation,101) as DateOfRequest,InboxStatusList.StatusNote,InBox.RecordNumber" +
                      " FROM         InboxStatusList INNER JOIN InBox ON InboxStatusList.Status = InBox.Status INNER JOIN " +
                      " UserDetails ON InBox.UserID = UserDetails.UD_UserPersonalID INNER JOIN " +
                     " RequestTypeList INNER JOIN  RequestList ON RequestTypeList.RequestTypeID = RequestList.RequestTypeID ON " +
                     "  UserDetails.UD_UserPersonalID = RequestList.RequesterID INNER JOIN " +
                     " UserDetails AS UserDetails_1 ON InBox.Requester = UserDetails_1.UD_UserPersonalID " +
                        " where InBox.UserID=1 ";
            EB.Generics.Generics commonClass = new EB.Generics.Generics();
            inboxDS = commonClass.ExecuteQuery(query);
            return inboxDS;
        }
        /// <summary>
        /// Please show how we can do this. 
        /// </summary>
        /// <param name="controlID"></param>
        /// <param name="linkID"></param>
        /// <returns></returns>
        UserControl LoadInBoxControl(string RequestType, string linkID)
        {
            return new UserControl();
        }

        UserControl LoadRequestGeneratorControl(string RequestType)
        {
            return new UserControl();
        }



        /// <summary>
        /// Login Check from Database
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="passWord"></param>
        /// <returns></returns>
        public int ValidateUserInformation(string userName, string passWord)
        {
            #region Fields
            object uid;
            int userId = 0;
            EB.Generics.Generics commonClass = new EB.Generics.Generics();
            string query = string.Empty;
            #endregion
            query = "SELECT UL_UserPersonalID FROM  UserList WHERE UL_UserName='" + userName + "' AND UL_Password='" + passWord + "'";
            uid = commonClass.ExecuteScalar(query);
            userId = Convert.ToInt32(uid);
            return userId;
        }

        public DataSet GetUsergroup()
        {
             #region Fields
            string query = string.Empty;
            DataSet userGroupDS;
            #endregion

            userGroupDS = new DataSet();
            query = "SELECT     US_GroupID, US_GroupName FROM         UserGroup";
            EB.Generics.Generics commonClass = new EB.Generics.Generics();
            userGroupDS = commonClass.ExecuteQuery(query);
            return userGroupDS;
        }
        #endregion


    }
}